package com.ysqcould.web.controller.revita;


import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.revita.domain.GslTowns;
import com.ysqcould.revita.service.IGslTownsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 乡村Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/revita/towns")
public class GslTownsController extends BaseController
{
    @Autowired
    private IGslTownsService gslTownsService;

    /**
     * 查询乡村列表
     */
    @PreAuthorize("@ss.hasPermi('revita:towns:list')")
    @GetMapping("/list")
    public TableDataInfo list(GslTowns gslTowns)
    {
        startPage();
        List<GslTowns> list = gslTownsService.selectGslTownsList(gslTowns);
        return getDataTable(list);
    }

    /**
     * 导出乡村列表
     */
    @PreAuthorize("@ss.hasPermi('revita:towns:export')")
    @Log(title = "乡村", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GslTowns gslTowns)
    {
        List<GslTowns> list = gslTownsService.selectGslTownsList(gslTowns);
        ExcelUtil<GslTowns> util = new ExcelUtil<GslTowns>(GslTowns.class);
        util.exportExcel(response, list, "乡村数据");
    }

    /**
     * 获取乡村详细信息
     */
    @PreAuthorize("@ss.hasPermi('revita:towns:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gslTownsService.selectGslTownsById(id));
    }

    /**
     * 获取乡村详细信息
     */
    @PreAuthorize("@ss.hasPermi('revita:towns:query')")
    @PostMapping("/townsList")
    public AjaxResult getTowns(@RequestBody GslTowns towns)
    {
        String val=towns.getCityName();
        return AjaxResult.success(gslTownsService.selectGslTown(val));
    }

    /**
     * 新增乡村
     */
    @PreAuthorize("@ss.hasPermi('revita:towns:add')")
    @Log(title = "乡村", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GslTowns gslTowns)
    {

        return toAjax(gslTownsService.insertGslTowns(gslTowns));
    }

    /**
     * 修改乡村
     */
    @PreAuthorize("@ss.hasPermi('revita:towns:edit')")
    @Log(title = "乡村", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GslTowns gslTowns)
    {
        return toAjax(gslTownsService.updateGslTowns(gslTowns));
    }

    /**
     * 删除乡村
     */
    @PreAuthorize("@ss.hasPermi('revita:towns:remove')")
    @Log(title = "乡村", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gslTownsService.deleteGslTownsByIds(ids));
    }
}
